package org.nowcoder.leetcode.BSearch;

/**
 * Title  : 162. Find Peak Element
 * Source : https://leetcode.cn/problems/find-peak-element/description/
 * Author : XrazYang
 * Date   : 2023-10-30
 */

public class LeetCode_162 {
    public int findPeakElement(int[] nums) {
        //最坏情况: O(n)
        int peek = nums[0], index = 0;
        if (nums.length > 1) {
            for (int i = 1; i < nums.length; i++) {
                if (peek > nums[i]) {
                    index = i - 1;
                    break;
                } else {
                    peek = nums[i];
                }
                index = i;
            }
        }
        return index;
    }
}
